﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MoroMoro.Tools.DDDProjector
{
    public partial class MainForm : Form, IParameters
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void _creationButton_Click(object sender, EventArgs e)
        {
            var destinationDirectoryPath = default(string);
            using (var dialog = new FolderBrowserDialog())
            {
                dialog.Description = "作成先を選択してください。";
                var showResult = dialog.ShowDialog(this);
                if (showResult != DialogResult.OK)
                {
                    return;
                }
                destinationDirectoryPath = dialog.SelectedPath;
            }


            var solutionDirectory = default(DirectoryInfo);
            try
            {
                var creator = new SolutionCreator(destinationDirectoryPath, this);
                solutionDirectory = creator.Create();
            }
            catch (UnauthorizedAccessException)
            {
                MessageBox.Show(this, "アクセス権がありません。", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var confirmResult = MessageBox.Show(this, "作成に成功しました。作成先のディレクトリを表示しますか？", "確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (confirmResult != DialogResult.Yes)
            {
                return;
            }

            Process.Start("explorer.exe", solutionDirectory.FullName);
        }

        #region IParameters メンバー

        string IParameters.DDDSolutionName
        {
            get
            {
                return _solutionNameTextBox.Text;
            }
        }

        string IParameters.OrganizationName
        {
            get
            {
                return _organizationNameTextBox.Text;
            }
        }

        string IParameters.BaseApplicationProjectName
        {
            get
            {
                return _applicationLayerSettingControl.BaseProjectName;
            }
        }

        string IParameters.BaseApplicationAssemblyName
        {
            get
            {
                return _applicationLayerSettingControl.BaseProjectAssemblyName;
            }
        }

        string IParameters.BaseApplicationNamespace
        {
            get
            {
                return _applicationLayerSettingControl.BaseProjectNamespace;
            }
        }

        string IParameters.MainApplicationProjectName
        {
            get
            {
                return _applicationLayerSettingControl.MainProjectName;
            }
        }

        string IParameters.MainApplicationAssemblyName
        {
            get
            {
                return _applicationLayerSettingControl.MainProjectAssemblyName;
            }
        }

        string IParameters.MainApplicationNamespace
        {
            get
            {
                return _applicationLayerSettingControl.MainProjectNamespace;
            }
        }

        string IParameters.BasePersistenceProjectName
        {
            get
            {
                return _persistenceLayerSettingControl.BaseProjectName;
            }
        }

        string IParameters.BasePersistenceAssemblyName
        {
            get
            {
                return _persistenceLayerSettingControl.BaseProjectAssemblyName;
            }
        }

        string IParameters.BasePersistenceNamespace
        {
            get
            {
                return _persistenceLayerSettingControl.BaseProjectNamespace;
            }
        }

        string IParameters.MainPersistenceProjectName
        {
            get
            {
                return _persistenceLayerSettingControl.MainProjectName;
            }
        }

        string IParameters.MainPersistenceAssemblyName
        {
            get
            {
                return _persistenceLayerSettingControl.MainProjectAssemblyName;
            }
        }

        string IParameters.MainPersistenceNamespace
        {
            get
            {
                return _persistenceLayerSettingControl.MainProjectNamespace;
            }
        }

        string IParameters.BaseDomainProjectName
        {
            get
            {
                return _domainLayerSettingControl.BaseProjectName;
            }
        }

        string IParameters.BaseDomainAssemblyName
        {
            get
            {
                return _domainLayerSettingControl.BaseProjectAssemblyName;
            }
        }

        string IParameters.BaseDomainNamespace
        {
            get
            {
                return _domainLayerSettingControl.BaseProjectNamespace;
            }
        }

        string IParameters.MainDomainProjectName
        {
            get
            {
                return _domainLayerSettingControl.MainProjectName;
            }
        }

        string IParameters.MainDomainAssemblyName
        {
            get
            {
                return _domainLayerSettingControl.MainProjectAssemblyName;
            }
        }

        string IParameters.MainDomainNamespace
        {
            get
            {
                return _domainLayerSettingControl.MainProjectNamespace;
            }
        }

        #endregion
    }
}
